package o;

import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.bumptech.glide.gifdecoder.GifDecoder;
import com.bumptech.glide.gifdecoder.GifDecoder.c;
import com.bumptech.glide.load.ImageHeaderParser;
import com.bumptech.glide.load.ImageHeaderParser.ImageType;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Queue;

public class xo implements se<ByteBuffer, xt> {
    private static final d ˋ = new d();
    private static final e ॱ = new e();
    private final d ʽ;
    private final e ˊ;
    private final Context ˎ;
    private final List<ImageHeaderParser> ˏ;
    private final xu ॱॱ;

    @VisibleForTesting
    static class d {
        d() {
        }

        GifDecoder ˊ(c cVar, rr rrVar, ByteBuffer byteBuffer, int i) {
            return new ru(cVar, rrVar, byteBuffer, i);
        }
    }

    @VisibleForTesting
    static class e {
        private final Queue<rt> ˋ = aau.ॱ(0);

        e() {
        }

        synchronized rt ˋ(ByteBuffer byteBuffer) {
            rt rtVar;
            rtVar = (rt) this.ˋ.poll();
            if (rtVar == null) {
                rtVar = new rt();
            }
            return rtVar.ˎ(byteBuffer);
        }

        synchronized void ॱ(rt rtVar) {
            rtVar.ˎ();
            this.ˋ.offer(rtVar);
        }
    }

    @androidx.annotation.Nullable
    private o.xs ˋ(java.nio.ByteBuffer r11, int r12, int r13, o.rt r14, o.sc r15) {
        /* JADX: method processing error */
/*
Error: jadx.core.utils.exceptions.JadxRuntimeException: Can't find block by offset: 0x003a in list [B:9:0x001e]
	at jadx.core.utils.BlockUtils.getBlockByOffset(BlockUtils.java:42)
	at jadx.core.dex.instructions.IfNode.initBlocks(IfNode.java:60)
	at jadx.core.dex.visitors.blocksmaker.BlockFinish.initBlocksInIfNodes(BlockFinish.java:48)
	at jadx.core.dex.visitors.blocksmaker.BlockFinish.visit(BlockFinish.java:33)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:31)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:17)
	at jadx.core.ProcessClass.process(ProcessClass.java:37)
	at jadx.api.JadxDecompiler.processClass(JadxDecompiler.java:306)
	at jadx.api.JavaClass.decompile(JavaClass.java:62)
*/
        /*
        r10 = this;
        r0 = 0;
        r7 = 2;
        r8 = o.aaq.ॱ();
        r2 = r14.ॱ();	 Catch:{ all -> 0x00c0 }
        r1 = r2.ˎ();	 Catch:{ all -> 0x00c0 }
        if (r1 <= 0) goto L_0x0016;	 Catch:{ all -> 0x00c0 }
    L_0x0010:
        r1 = r2.ˏ();	 Catch:{ all -> 0x00c0 }
        if (r1 == 0) goto L_0x003b;
    L_0x0016:
        r1 = "BufferGifDecoder";
        r1 = android.util.Log.isLoggable(r1, r7);
        if (r1 == 0) goto L_0x003a;
    L_0x001e:
        r1 = "BufferGifDecoder";
        r2 = new java.lang.StringBuilder;
        r2.<init>();
        r3 = "Decoded GIF from stream in ";
        r2 = r2.append(r3);
        r4 = o.aaq.ˎ(r8);
        r2 = r2.append(r4);
        r2 = r2.toString();
        android.util.Log.v(r1, r2);
    L_0x003a:
        return r0;
    L_0x003b:
        r1 = o.xx.ˎ;	 Catch:{ all -> 0x00c0 }
        r1 = r15.ॱ(r1);	 Catch:{ all -> 0x00c0 }
        r3 = com.bumptech.glide.load.DecodeFormat.PREFER_RGB_565;	 Catch:{ all -> 0x00c0 }
        if (r1 != r3) goto L_0x0084;	 Catch:{ all -> 0x00c0 }
    L_0x0045:
        r1 = android.graphics.Bitmap.Config.RGB_565;	 Catch:{ all -> 0x00c0 }
    L_0x0047:
        r3 = ˋ(r2, r12, r13);	 Catch:{ all -> 0x00c0 }
        r4 = r10.ʽ;	 Catch:{ all -> 0x00c0 }
        r5 = r10.ॱॱ;	 Catch:{ all -> 0x00c0 }
        r2 = r4.ˊ(r5, r2, r11, r3);	 Catch:{ all -> 0x00c0 }
        r2.ॱ(r1);	 Catch:{ all -> 0x00c0 }
        r2.ˋ();	 Catch:{ all -> 0x00c0 }
        r6 = r2.ʼ();	 Catch:{ all -> 0x00c0 }
        if (r6 != 0) goto L_0x0087;
    L_0x005f:
        r1 = "BufferGifDecoder";
        r1 = android.util.Log.isLoggable(r1, r7);
        if (r1 == 0) goto L_0x003a;
    L_0x0067:
        r1 = "BufferGifDecoder";
        r2 = new java.lang.StringBuilder;
        r2.<init>();
        r3 = "Decoded GIF from stream in ";
        r2 = r2.append(r3);
        r4 = o.aaq.ˎ(r8);
        r2 = r2.append(r4);
        r2 = r2.toString();
        android.util.Log.v(r1, r2);
        goto L_0x003a;
    L_0x0084:
        r1 = android.graphics.Bitmap.Config.ARGB_8888;	 Catch:{ all -> 0x00c0 }
        goto L_0x0047;	 Catch:{ all -> 0x00c0 }
    L_0x0087:
        r3 = o.wg.ˋ();	 Catch:{ all -> 0x00c0 }
        r0 = new o.xt;	 Catch:{ all -> 0x00c0 }
        r1 = r10.ˎ;	 Catch:{ all -> 0x00c0 }
        r4 = r12;	 Catch:{ all -> 0x00c0 }
        r5 = r13;	 Catch:{ all -> 0x00c0 }
        r0.<init>(r1, r2, r3, r4, r5, r6);	 Catch:{ all -> 0x00c0 }
        r1 = new o.xs;	 Catch:{ all -> 0x00c0 }
        r1.<init>(r0);	 Catch:{ all -> 0x00c0 }
        r0 = "BufferGifDecoder";
        r0 = android.util.Log.isLoggable(r0, r7);
        if (r0 == 0) goto L_0x00bd;
    L_0x00a1:
        r0 = "BufferGifDecoder";
        r2 = new java.lang.StringBuilder;
        r2.<init>();
        r3 = "Decoded GIF from stream in ";
        r2 = r2.append(r3);
        r4 = o.aaq.ˎ(r8);
        r2 = r2.append(r4);
        r2 = r2.toString();
        android.util.Log.v(r0, r2);
    L_0x00bd:
        r0 = r1;
        goto L_0x003a;
    L_0x00c0:
        r0 = move-exception;
        r1 = "BufferGifDecoder";
        r1 = android.util.Log.isLoggable(r1, r7);
        if (r1 == 0) goto L_0x00e5;
    L_0x00c9:
        r1 = "BufferGifDecoder";
        r2 = new java.lang.StringBuilder;
        r2.<init>();
        r3 = "Decoded GIF from stream in ";
        r2 = r2.append(r3);
        r4 = o.aaq.ˎ(r8);
        r2 = r2.append(r4);
        r2 = r2.toString();
        android.util.Log.v(r1, r2);
    L_0x00e5:
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.xo.ˋ(java.nio.ByteBuffer, int, int, o.rt, o.sc):o.xs");
    }

    public /* synthetic */ tx ˎ(@NonNull Object obj, int i, int i2, @NonNull sc scVar) throws IOException {
        return ˊ((ByteBuffer) obj, i, i2, scVar);
    }

    public xo(Context context, List<ImageHeaderParser> list, uc ucVar, ud udVar) {
        this(context, list, ucVar, udVar, ॱ, ˋ);
    }

    @VisibleForTesting
    xo(Context context, List<ImageHeaderParser> list, uc ucVar, ud udVar, e eVar, d dVar) {
        this.ˎ = context.getApplicationContext();
        this.ˏ = list;
        this.ʽ = dVar;
        this.ॱॱ = new xu(ucVar, udVar);
        this.ˊ = eVar;
    }

    public boolean ˊ(@NonNull ByteBuffer byteBuffer, @NonNull sc scVar) throws IOException {
        return !((Boolean) scVar.ॱ(xx.ˏ)).booleanValue() && rx.ˎ(this.ˏ, byteBuffer) == ImageType.GIF;
    }

    public xs ˊ(@NonNull ByteBuffer byteBuffer, int i, int i2, @NonNull sc scVar) {
        rt ˋ = this.ˊ.ˋ(byteBuffer);
        try {
            xs ˋ2 = ˋ(byteBuffer, i, i2, ˋ, scVar);
            return ˋ2;
        } finally {
            this.ˊ.ॱ(ˋ);
        }
    }

    private static int ˋ(rr rrVar, int i, int i2) {
        int min = Math.min(rrVar.ˊ() / i2, rrVar.ॱ() / i);
        min = Math.max(1, min == 0 ? 0 : Integer.highestOneBit(min));
        if (Log.isLoggable("BufferGifDecoder", 2) && min > 1) {
            Log.v("BufferGifDecoder", "Downsampling GIF, sampleSize: " + min + ", target dimens: [" + i + "x" + i2 + "], actual dimens: [" + rrVar.ॱ() + "x" + rrVar.ˊ() + "]");
        }
        return min;
    }
}
